﻿using System.Drawing;
using System.Windows.Forms;
using TestStepsEditor.Viewers.Data;

namespace TestStepsEditor.Actions
{
    internal class InsertImages
    {
        public static SharedData AddImageToGrid(SharedData data)
        {
            var image = Image.FromFile(@".\Images\paperclip.gif");
            foreach (DataGridViewRow item in data.GridView.Rows)
            {
                if (item.Cells["Title"].Value != null && item.Cells["SharedStep"].Value.Equals(true))
                {
                    item.ReadOnly = true;
                    item.DefaultCellStyle.ForeColor = Color.Gray;
                }
                if (item.Cells["Attachment"].Value != null)
                {
                    item.Cells["image"].Value = image;
                }
                else
                {
                    var dataGridViewCellStyle =
                        new DataGridViewCellStyle {NullValue = null, Tag = "BLANK"};
                    item.Cells["image"].Style = dataGridViewCellStyle;
                }
            }
            if (data.GridView != null)
// ReSharper disable PossibleNullReferenceException
                data.GridView.Columns["image"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
// ReSharper restore PossibleNullReferenceException

            return data;
        }
    }
}